package com.base.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName: RedisConfig
 * @Description: redis工具类
 * @Author: CJQ
 * @Date: 2021/2/7 14:47
 */
@Component
public class RedisUtil {

    @Autowired
    private RedisTemplate redisTemplate;

    //redisTemplate.opsForValue();//操作字符串
    //redisTemplate.opsForHash();//操作hash
    //redisTemplate.opsForList();//操作list
    //redisTemplate.opsForSet();//操作set
    //redisTemplate.opsForZSet();//操作有序set

    /**
     * redis存值
     *
     * @param key
     * @param value
     * @param time  过期时间（s）
     */
    public void setValue(String key, Object value, int time) {
        redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
    }

    /**
     * redis取值
     *
     * @param key
     */
    public Object getValue(String key) {
        Object obj = redisTemplate.opsForValue().get(key);
        return obj;
    }


}
